define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'room/room/index' + location.search,
                    add_url: 'room/room/add',
                    edit_url: 'room/room/edit',
                    del_url: 'room/room/del',
                    multi_url: 'room/room/multi',
                    import_url: 'room/room/import',
                    table: 'room',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'users.nickname', title: __('Users_id')},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
                        // {field: 'longitude', title: __('Longitude'), operate:'BETWEEN'},
                        // {field: 'latitude', title: __('Latitude'), operate:'BETWEEN'},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'sex', title: __('Sex'), searchList: {"0":__('Sex 0'),"1":__('Sex 1')}, formatter: Table.api.formatter.normal},
                        {field: 'hire_type', title: __('Hire_type'), searchList: {"0":__('Hire_type 0'),"1":__('Hire_type 1')}, formatter: Table.api.formatter.normal},
                        {field: 'room_name', title: __('Room_name'), operate: 'LIKE'},
                        {field: 'province', title: __('Province'), operate: 'LIKE'},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'region', title: __('Region'), operate: 'LIKE'},
                        {field: 'shi', title: __('Shi')},
                        {field: 'ting', title: __('Ting')},
                        {field: 'wei', title: __('Wei')},
                        {field: 'face', title: __('Face'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'room_area', title: __('Room_area')},
                        {field: 'room_height', title: __('Room_height'), operate: 'LIKE'},
                        {field: 'room_price', title: __('Room_price'), operate:'BETWEEN'},
                        {field: 'amount_type', title: __('Amount_type'), searchList: {"0":__('Amount_type 0'),"1":__('Amount_type 1'),"2":__('Amount_type 2'),"3":__('Amount_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'renovation_type', title: __('Renovation_type'), searchList: {"0":__('Renovation_type 0'),"1":__('Renovation_type 1'),"2":__('Renovation_type 2'),"3":__('Renovation_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'room_type', title: __('Room_type'), searchList: {"0":__('Room_type 0'),"1":__('Room_type 1'),"2":__('Room_type 2'),"3":__('Room_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'lift', title: __('Lift'), searchList: {"0":__('Lift 0'),"1":__('Lift 1')}, formatter: Table.api.formatter.normal},
                        {field: 'sale_room_date', title: __('Sale_room_date'), operate: 'LIKE'},
                        {field: 'see_times', title: __('See_times'), operate: 'LIKE'},
                        {field: 'in_times', title: __('In_times'), operate: 'LIKE'},
                        {field: 'contain_amount', title: __('Contain_amount'), operate: 'LIKE'},
                        {field: 'first_images', title: __('First_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'out_images', title: __('Out_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'videos', title: __('Videos'), formatter: Table.api.formatter.files},
                        {field: 'tags_text', title: __('Tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'wx_code', title: __('Wx_code'), operate: 'LIKE'},
                        {field: 'qq_code', title: __('Qq_code'), operate: 'LIKE'},
                        {field: 'whats_code', title: __('Whats_code'), operate: 'LIKE'},
                        {field: 'room_describe', title: __('Room_describe'), operate: 'LIKE'},
                        {field: 'like', title: __('Like')},
                        {field: 'collect', title: __('Collect')},
                        // {field: 'hot', title: __('Hot')},
                        {field: 'browse', title: __('Browse')},
                        {field: 'subway', title: __('Subway'), operate: 'LIKE'},
                        {field: 'start_price', title: __('Start_price'), operate:'BETWEEN'},
                        {field: 'end_price', title: __('End_price'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
